home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / comms / non-internet / samba / docs / encryption.txt < prev    next >
Text File  |  1996-06-26  |  13KB  |  334 lines

  1.         LanManager / Samba Password Encryption.
  2.         ---------------------------------------
  3.  
  4. With the development of LanManager compatible password encryption for
  5. Samba, it is now able to validate user connections in exactly the same
  6. way as a LanManager or Windows NT server.
  7.  
  8. This document describes how the SMB password encryption algorithm
  9. works and what issues there are in choosing whether you want to use
  10. it. You should read it carefully, especially the part about security
  11. and the "PROS and CONS" section.
  12.  
  13. How does it work ?
  14. ------------------
  15.  
  16.     LanManager encryption is somewhat similar to UNIX password
  17. encryption. The server uses a file containing a hashed value of a
  18. users password.  This is created by taking the users paintext
  19. password, capitalising it, and either truncating to 14 bytes (or
  20. padding to 14 bytes with null bytes). This 14 byte value is used as
  21. two 56 bit DES keys to encrypt a 'magic' eight byte value, forming a
  22. 16 byte value which is stored by the server and client. Let this value
  23. be known as the *hashed password*.
  24.  
  25. When a client (LanManager, Windows for WorkGroups, Windows 95 or
  26. Windows NT) wishes to mount a Samba drive (or use a Samba resource) it
  27. first requests a connection and negotiates the protocol that the client
  28. and server will use. In the reply to this request the Samba server
  29. generates and appends an 8 byte, random value - this is stored in the
  30. Samba server after the reply is sent and is known as the *challenge*.
  31.  
  32. The challenge is different for every client connection.
  33.  
  34. The client then uses the hashed password (16 byte value described
  35. above), appended with 5 null bytes, as three 56 bit DES keys, each of
  36. which is used to encrypt the challenge 8 byte value, forming a 24 byte
  37. value known as the *response*.
  38.  
  39. In the SMB call SMBsessionsetupX (when user level security is
  40. selected) or the call SMBtconX (when share level security is selected)
  41. the 24 byte response is returned by the client to the Samba server.
  42.  
  43. The Samba server then reproduces the above calculation, using it's own
  44. stored value of the 16 byte hashed password (read from the smbpasswd
  45. file - described later) and the challenge value that it kept from the
  46. negotiate protocol reply. It then checks to see if the 24 byte value it
  47. calculates matches the 24 byte value returned to it from the client.
  48.  
  49. If these values match exactly, then the client knew the correct
  50. password (or the 16 byte hashed value - see security note below) and
  51. is this allowed access. If not then the client did not know the
  52. correct password and is denied access.
  53.  
  54. Note that the Samba server never knows or stores the cleartext of the
  55. users password - just the 16 byte hashed function derived from it. Also
  56. note that the cleartext password or 16 byte hashed value are never
  57. transmitted over the network - thus increasing security.
  58.  
  59. IMPORTANT NOTE ABOUT SECURITY
  60. -----------------------------
  61.  
  62. The unix and SMB password encryption techniques seem similar on the
  63. surface. This similarity is, however, only skin deep. The unix scheme
  64. typically sends clear text passwords over the nextwork when logging
  65. in. This is bad. The SMB encryption scheme never sends the cleartext
  66. password over the network but it does store the 16 byte hashed value
  67. on disk. This is also bad. Why? Because the 16 byte hashed value is a
  68. "password equivalent". You cannot derive the users password from it,
  69. but it could potentially be used in a modified client to gain access
  70. to a server. This would require considerable technical knowledge on
  71. behalf of the attacker but is perfectly possible. You should thus
  72. treat the smbpasswd file as though it contained the cleartext
  73. passwords of all your users. Its contents must be kept secret, and the
  74. file should be protected accordingly.
  75.  
  76. Ideally we would like a password scheme which neither requires plain
  77. text passwords on the net or on disk. Unfortunately this is not
  78. available as Samba is stuck with being compatible with other SMB
  79. systems (WinNT, WfWg, Win95 etc). 
  80.  
  81.  
  82. PROS AND CONS
  83. -------------
  84.  
  85. There are advantages and disadvantages to both schemes. 
  86.  
  87. Advantages of SMB Encryption:
  88. -----------------------------
  89.  
  90. - plain text passwords are not passed across the network. Someone using
  91. a network sniffer cannot just record passwords going to the SMB server.
  92.  
  93. - WinNT doesn't like talking to a server that isn't using SMB
  94. encrypted passwords. It will refuse to browse the server if the server
  95. is also in user level security mode. It will insist on promting the
  96. user for the password on each connection, which is very annoying. The
  97. only things you can do to stop this is to use SMB encryption.
  98.  
  99. Advantages of non-encrypted passwords:
  100. --------------------------------------
  101.  
  102. - plain text passwords are not kept on disk. 
  103.  
  104. - uses same password file as other unix services such as login and
  105. ftp
  106.  
  107. - you are probably already using other services (such as telnet and
  108. ftp) which send plain text passwords over the net, so not sending them
  109. for SMB isn't such a big deal.
  110.  
  111. - the SMB encryption code in Samba is new and has only had limited
  112. testing. We have tried hard to make it secure but in any new
  113. implementation of a password scheme there is the possability of an
  114. error. 
  115.  
  116.  
  117. The smbpasswd file.
  118. -------------------
  119.  
  120.     In order for Samba to participate in the above protocol it must
  121. be able to look up the 16 byte hashed value given a user name.
  122. Unfortunately, as the UNIX password value is also a one way hash
  123. function (ie. it is impossible to retrieve the cleartext of the users
  124. password given the UNIX hash of it) then a separate password file
  125. containing this 16 byte value must be kept. To minimise problems with
  126. these two password files, getting out of sync, the UNIX /etc/passwd and
  127. the smbpasswd file, a utility, mksmbpasswd.sh, is provided to generate
  128. a smbpasswd file from a UNIX /etc/passwd file.
  129.  
  130. To generate the smbpasswd file from your /etc/passwd file use the
  131. following command :-
  132.  
  133. cat /etc/passwd | mksmbpasswd.sh >/usr/local/samba/private/smbpasswd
  134.  
  135. If you are running on a system that uses NIS, use
  136.  
  137. ypcat passwd | mksmbpasswd.sh >/usr/local/samba/private/smbpasswd
  138.  
  139. The mksmbpasswd.sh program is found in the Samba source directory. By
  140. default, the smbpasswd file is stored in :-
  141.  
  142. /usr/local/samba/private/smbpasswd
  143.  
  144. The owner of the /usr/local/samba/private directory should be set to
  145. root, and the permissions on it should be set to :-
  146.  
  147. r-x------
  148.  
  149. The command 
  150.  
  151. chmod 500 /usr/local/samba/private
  152.  
  153. will do the trick. Likewise, the smbpasswd file inside the private
  154. directory should be owned by root and the permissions on is should be
  155. set to
  156.  
  157. rw-------
  158.  
  159. by the command :-
  160.  
  161. chmod 600 smbpasswd.
  162.  
  163. The format of the smbpasswd file is
  164.  
  165. username:uid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:Long name:user home dir:user shell
  166.  
  167. Although only the username, uid, and XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  168. sections are significant and are looked at in the Samba code.
  169.  
  170. It is *VITALLY* important that there by 32 'X' characters between the
  171. two ':' characters - the smbpasswd and Samba code will fail to validate
  172. any entries that do not have 32 characters between ':' characters.
  173.  
  174. When the password file is created all users have password entries
  175. consisting of 32 'X' characters. By default this disallows any access
  176. as this user. When a user has a password set, the 'X' characters change
  177. to 32 ascii hexadecimal digits (0-9, A-F). These are an ascii
  178. representation of the 16 byte hashed value of a users password.
  179.  
  180. To set a user to have no password (not recommended), edit the file
  181. using vi, and replace the first 11 characters with the asci text
  182.  
  183. NO PASSWORD
  184.  
  185. Eg. To clear the password for user bob, his smbpasswd file entry would
  186. look like :
  187.  
  188. bob:100:NO PASSWORDXXXXXXXXXXXXXXXXXXXXX:Bob's full name:/bobhome:/bobshell
  189.  
  190. If you are allowing users to use the smbpasswd command to set their own
  191. passwords, you may want to give users NO PASSWORD initially so they do
  192. not have to enter a previous password when changing to their new
  193. password (not recommended).
  194.  
  195. Note : This file should be protected very carefully. Anyone with
  196. access to this file can (with enough knowledge of the protocols) gain
  197. access to your SMB server. The file is thus more sensitive than a
  198. normal unix /etc/passwd file.
  199.  
  200. The smbpasswd Command.
  201. ----------------------
  202.  
  203.     The smbpasswd command maintains the 32 byte password field in
  204. the smbpasswd file. If you wish to make it similar to the unix passwd
  205. or yppasswd programs, install it in /usr/local/samba/bin (or your main
  206. Samba binary directory) and make it setuid root.
  207.  
  208. Note that if you do not do this then the root user will have to set all
  209. users passwords.
  210.  
  211. To set up smbpasswd as setuid root, change to the Samba binary install
  212. directory and then type (as root) :
  213.  
  214. chown root smbpasswd
  215. chmod 4555 smbpasswd
  216.  
  217. If smbpasswd is installed as setuid root then you would use it as
  218. follows.
  219.  
  220. smbpasswd
  221. Old SMB password: <type old alue here - just hit return if there is NO PASSWORD>
  222. New SMB Password: < type new value >
  223. Repeat New SMB Password: < re-type new value >
  224.  
  225. If the old value does not match the current value stored for that user,
  226. or the two new values do not match each other, then the password will
  227. not be changed.
  228.  
  229. If invoked by an ordinary user it will only allow the user to change
  230. his or her own Samba password.
  231.  
  232. If run by the root user smbpasswd may take an optional argument,
  233. specifying the user name whose SMB password you wish to change.  Note
  234. that when run as root smbpasswd does not prompt for or check the old
  235. password value, thus allowing root to set passwords for users who have
  236. forgotten their passwords.
  237.  
  238. smbpasswd is designed to work in the same way and be familiar to UNIX
  239. users who use the passwd or yppasswd commands.
  240.  
  241. NOTE. As smbpasswd is designed to be installed as setuid root I would
  242. appreciate it if everyone examined the source code to look for
  243. potential security flaws. A setuid program, if not written properly can
  244. be an open door to a system cracker. Please help make this program
  245. secure by reporting all problems to me (the author, Jeremy Allison).
  246.  
  247. My email address is :-
  248.  
  249. jra@vantive.com
  250.  
  251. Setting up Samba to support LanManager Encryption.
  252. --------------------------------------------------
  253.  
  254. This is a very brief description on how to setup samba to support
  255. password encryption. More complete instructions will probably be added
  256. later.
  257.  
  258. 1) get and compile the libdes libraries. the source is available from
  259. nimbus.anu.edu.au in pub/tridge/libdes/libdes.tar.92-10-13.gz
  260.  
  261. 2) enable the encryption stuff in the Samba makefile, making sure you
  262. point it to the libdes library and include file (it needs des.h)
  263. The entries you need to uncomment are the four lines after the comment :-
  264.  
  265. # This is for SMB encrypted (lanman) passwords.
  266.  
  267. Note that you may have to change the variable DES_BASE to
  268. point at the place where you installed the DES library.
  269.  
  270. 3) compile and install samba as usual
  271.  
  272. 4) f your system can't compile the module getsmbpass.c then remove the
  273. -DSMBGETPASS define from the Makefile.
  274.  
  275. 5) enable encrypted passwords in smb.conf by adding the line 
  276. "encrypt passwords = yes" in the [global] section
  277.  
  278. 6) create the initial smbpasswd password file in the place you
  279. specified in the Makefile. A simple way to do this based on your
  280. existing Makefile (assuming it is in a reasonably standard format) is
  281. like this:
  282.  
  283. cat /etc/passwd | mksmbpasswd.sh > /usr/local/samba/private/smbpasswd
  284.  
  285. Change ownership of private and smbpasswd to root.
  286.  
  287. chown -R root /usr/local/samba/private
  288.  
  289. Set the correct permissions on /usr/local/samba/private
  290.  
  291. chmod 500 /usr/local/samba/private
  292.  
  293. Set the correct permissions on /usr/local/samba/private/smbpasswd
  294.  
  295. chmod 600 /usr/local/samba/private/smbpasswd
  296.  
  297. note that the mksmbpasswd.sh script is in the samba source directory.
  298.  
  299. If this fails then you will find that you will need entries that look
  300. like this:
  301.  
  302. # SMB password file.
  303. tridge:148:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:Andrew Tridgell:/home/tridge:/bin/tcsh
  304.  
  305. note that the uid and username fields must be right. Also, you must get
  306. the number of X's right (there should be 32).
  307.  
  308. If you wish, install the smbpasswd program as suid root.
  309.  
  310. chown root /usr/local/samba/bin/smbpasswd
  311. chmod 4555 /usr/local/samba/bin/smbpasswd
  312.  
  313. 7) set the passwords for users using the smbpasswd command. For
  314. example, as root you could do "smbpasswd tridge"
  315.  
  316. 8) try it out!
  317.  
  318. Note that you can test things using smbclient, as it also now supports
  319. encryption.
  320.  
  321. NOTE TO USA Sites that Mirror Samba
  322. -----------------------------------
  323.  
  324. The DES library is considered a munition in the USA. Under US Law it is
  325. illegal to export this software, or to put it in a freely available ftp
  326. site.
  327.  
  328. Please do not mirror the DES directory from the site on nimbus.anu.edu.au
  329.  
  330. Thank you,
  331.  
  332. Jeremy Allison.
  333.  
  334.